package com.notes.algo.t8;

import java.util.*;
public class Test{
    public static void main(String arg[]){
        //获取输入股票价格
        Scanner input = new Scanner(System.in);
        String priceString = "10,5,1,2,3,5,3,3,1,2,2,10";
        //分解每日股票价格到字符串数组
        String[] pricrStringArray = priceString.split(",");
        //priceSet存放去重的股票价格
        Set<Integer> priceSet = new HashSet<>();
        //priceMap存放股票价格对应的出现次数
        Map<Integer,Integer> priceMap = new HashMap<>();
        //更新股票价格对应的出现次数
        for(int i = 0; i<pricrStringArray.length; i++){
            int number = Integer.parseInt(pricrStringArray[i]);
            priceSet.add(number);
            int priceKey = number;
            Integer priceNumber = priceMap.get(priceKey);
            //首次出现的股票价格，次数设置为1
            if(priceNumber==null){
                priceNumber = 1;
                priceMap.put(priceKey, priceNumber);

            }else{//先前记录过的股票价格，出现次数加一
                //priceValue = priceMap.get(priceKey);
                priceNumber++;
                priceMap.put(priceKey, priceNumber);
            }

        }
        int[] priceArray = new int[priceSet.size()];
        int foot=0;
        for(int set: priceSet){
            priceArray[foot] = set;
            foot++;
        }
        //股票价格排序
        Arrays.sort(priceArray);
        //从大到小输出股票价格与其对应的出现次数
        for(int j=0; j<priceArray.length; j++){
            int value = priceMap.get(priceArray[j]);
            System.out.println(priceArray[j]+","+value);
        }

    }
}
